﻿<navigation:Page x:Class="Groceries.Views.ShoppingLists"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:datagrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:riacontrols="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Ria"
           xmlns:ds="clr-namespace:Groceries.Web.Services"
           xmlns:riadata="clr-namespace:System.Windows.Data;assembly=System.Windows.Controls.Ria"
           xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
           xmlns:activity="clr-namespace:System.Windows.Controls;assembly=ActivityControl"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="ShoppingLists">
  <Grid x:Name="LayoutRoot">
    <Grid.Resources>
      <ds:GroceriesDomainContext x:Key="groceriesDomainContext" />
    </Grid.Resources>

    <riacontrols:DomainDataSource x:Name="shoppingListData" LoadSize="100" QueryName="GetShoppingLists" AutoLoad="True" DomainContext="{Binding Source={StaticResource groceriesDomainContext}}" >
      <riacontrols:DomainDataSource.FilterDescriptors>
        <riadata:FilterDescriptorCollection>
          <riadata:FilterDescriptor PropertyPath="Name" Operator="Contains">
            <riacontrols:ControlParameter ControlName="txtNameFilter" ParameterName="Text" RefreshEventName="TextChanged"/>
          </riadata:FilterDescriptor>
        </riadata:FilterDescriptorCollection>
      </riacontrols:DomainDataSource.FilterDescriptors>
    </riacontrols:DomainDataSource>



    <ScrollViewer BorderThickness="0" VerticalScrollBarVisibility="Auto" Padding="0,12,0,12"
            Margin="-12">

      <activity:Activity IsActive="{Binding ElementName=shoppingListData,Path=IsBusy}">
        <StackPanel Margin="0,12,0,12" Orientation="Vertical">
          <TextBlock Text="Shopping Lists" Style="{StaticResource HeaderTextStyle}"/>
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0">
            <TextBlock Text="Name Filter: " VerticalAlignment="Center"/>
            <TextBox x:Name="txtNameFilter" Width="75" FontSize="11" Margin="4"/>
          </StackPanel>
          <datagrid:DataGrid x:Name="shoppingListGrid" MinHeight="100"
                         ItemsSource="{Binding ElementName=shoppingListData, Path=Data}" IsReadOnly="True" AutoGenerateColumns="False">
            <datagrid:DataGrid.Columns>
              <datagrid:DataGridTemplateColumn>
                <datagrid:DataGridTemplateColumn.CellTemplate>
                  <DataTemplate>
                    <Button Click="Button_Click" Cursor="Hand" Content="Open List" Margin="10,0,10,0" />
                  </DataTemplate>
                </datagrid:DataGridTemplateColumn.CellTemplate>
              </datagrid:DataGridTemplateColumn>
              
              <!--<datagrid:DataGridTemplateColumn>
                <datagrid:DataGridTemplateColumn.CellTemplate>
                  <DataTemplate>
                    <HyperlinkButton x:Name="linkOpen" NavigateUri="/ShoppingListDetails?Id={ID}" TargetName="ContentFrame" Content="Open List"/>
                  </DataTemplate>
                </datagrid:DataGridTemplateColumn.CellTemplate>
              </datagrid:DataGridTemplateColumn>-->
              
              <datagrid:DataGridTextColumn Header="Name" Width="200"
                Binding="{Binding Name}" />

              <datagrid:DataGridTextColumn Header="Amount of Items" Width="200"
                Binding="{Binding ShoppingListsItems.Count}" />

              <datagrid:DataGridTextColumn Header="Date Modified" Width="200"
                Binding="{Binding DateModified}" />

            </datagrid:DataGrid.Columns>
          </datagrid:DataGrid>

          <datagrid:DataPager x:Name="itemPager" PageSize="20" Margin="0,-1,0,0"
                          Source="{Binding ElementName=shoppingListData,Path=Data}"/>

          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
            <Button x:Name="AddListButton" Content="Add New List" Width="90" Height="23" Margin="4,0,0,0"
                    Click="AddListButton_Click"/>
          </StackPanel>

          <dataform:DataForm x:Name="shoppingListDetails" Header="Details" CurrentItem="{Binding ElementName=shoppingListGrid,Path=SelectedItem}"
          Margin="0,12,0,0" AutoCommit="False" AutoEdit="True">
            <dataform:DataForm.EditTemplate>
              <DataTemplate>
                <StackPanel>
                  <dataform:DataField Label="Name">
                    <TextBox Text="{Binding Name,Mode=TwoWay}"/>
                  </dataform:DataField>
                </StackPanel>
              </DataTemplate>
            </dataform:DataForm.EditTemplate>
          </dataform:DataForm>

          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
            <Button Content="Save Changes" x:Name="buttonSave" Width="120" Height="23" Margin="4,0,0,0" Click="buttonSave_Click" />
          </StackPanel>
        </StackPanel>
      </activity:Activity>
    </ScrollViewer>
  </Grid>
</navigation:Page>
